package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理端-订单管理")
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    //注入OrderService
    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索:{}",ordersPageQueryDTO);

        //调用service搜索订单
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);

        //返回结果给前端
        return Result.success(pageResult);
    }

    @ApiOperation(value = "各个状态的订单状态统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("各个状态的订单状态统计");

        //调用service统计订单
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();

        //返回结果给前端
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     * @return
     */
    @ApiOperation(value = "订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> detail(@PathVariable("id") Long id){
        log.info("订单详情,{}",id);

        //调用service查询订单详情
        OrderVO orderVO = orderService.details(id);

        //返回结果给前端
        return Result.success(orderVO);
    }

    @ApiOperation(value = "接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单,{}",ordersConfirmDTO);

        //调用service接单
        orderService.confirm(ordersConfirmDTO);

        //返回结果给前端
        return Result.success();
    }

    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation(value = "拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单,{}",ordersRejectionDTO);

        //调用service拒单
        orderService.rejection(ordersRejectionDTO);

        //返回结果给前端
        return Result.success();
    }

    @ApiOperation(value = "取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单,{}",ordersCancelDTO);

        //调用service取消订单
        orderService.cancel(ordersCancelDTO);

        //返回结果给前端
        return Result.success();
    }


    /**
     * 订单派送
     * @param id
     * @return
     */
    @ApiOperation(value = "订单派送")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id){
        log.info("订单派送,{}",id);

        //调用service派送
        orderService.delivery(id);

        //返回结果给前端
        return Result.success();
    }

    /**
     * 订单完成
     * @param id
     * @return
     */
    @ApiOperation(value = "订单完成")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long id){
        log.info("订单完成,{}",id);

        //调用service完成
        orderService.complete(id);

        //返回结果给前端
        return Result.success();
    }



}
